<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blogwebpage/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blogwebpage/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/blogwebpage/images/favicon.ico">
  <link rel="mask-icon" href="/blogwebpage/images/logo.svg" color="#222">
  <meta name="msvalidate.01" content="9BDlx6FiNE">

<link rel="stylesheet" href="/blogwebpage/css/main.css">


<link rel="stylesheet" href="/blogwebpage/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wangkejie.gitee.io","root":"/blogwebpage/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="ipa解包后结构:  可执行文件 Mach-O 64-bit executable arm64 Mach-O executable arm_v7   .car，资源打包文件 .nib、.bundle、Localizable.strings _CodeSignature签名文件 文件hash列表：存放每个文件的hash值；  XML结构   .mobileprovision   可执行文件Mach-">
<meta property="og:type" content="article">
<meta property="og:title" content="ipa包分析">
<meta property="og:url" content="https://wangkejie.gitee.io/blogwebpage/iOS/interview/ipaanalysis.html">
<meta property="og:site_name" content="王科杰">
<meta property="og:description" content="ipa解包后结构:  可执行文件 Mach-O 64-bit executable arm64 Mach-O executable arm_v7   .car，资源打包文件 .nib、.bundle、Localizable.strings _CodeSignature签名文件 文件hash列表：存放每个文件的hash值；  XML结构   .mobileprovision   可执行文件Mach-">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://wangkejie.gitee.io/blogwebpage/images/iOS/macho_construction.png">
<meta property="article:published_time" content="2017-07-15T03:26:39.000Z">
<meta property="article:modified_time" content="2021-06-25T08:55:53.145Z">
<meta property="article:author" content="Jack Wang">
<meta property="article:tag" content="ipa包分析">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://wangkejie.gitee.io/blogwebpage/images/iOS/macho_construction.png">

<link rel="canonical" href="https://wangkejie.gitee.io/blogwebpage/iOS/interview/ipaanalysis.html">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ipa包分析 | 王科杰</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?93e26277de0cf2c5851167f2c6dcaa7d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blogwebpage/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">王科杰</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Jack's Notes</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blogwebpage/" rel="section"><i class="home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blogwebpage/archives/" rel="section"><i class="archive fa-fw"></i>归档<span class="badge">52</span></a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blogwebpage/me/" rel="section"><i class="user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blogwebpage/tags/" rel="section"><i class="tags fa-fw"></i>标签<span class="badge">54</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blogwebpage/categories/" rel="section"><i class="th fa-fw"></i>分类<span class="badge">56</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL0phY2stVmluZw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wangkejie.gitee.io/blogwebpage/iOS/interview/ipaanalysis.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blogwebpage/images/avatar.gif">
      <meta itemprop="name" content="Jack Wang">
      <meta itemprop="description" content="书山有路勤为径，学海无涯苦作舟！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="王科杰">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ipa包分析
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-07-15 11:26:39" itemprop="dateCreated datePublished" datetime="2017-07-15T11:26:39+08:00">2017-07-15</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blogwebpage/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blogwebpage/categories/iOS/%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/" itemprop="url" rel="index"><span itemprop="name">面试总结</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blogwebpage/categories/iOS/%E9%9D%A2%E8%AF%95%E6%80%BB%E7%BB%93/ipa%E5%8C%85%E5%88%86%E6%9E%90/" itemprop="url" rel="index"><span itemprop="name">ipa包分析</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>ipa解包后结构:</p>
<ul>
<li>可执行文件<ul>
<li>Mach-O 64-bit executable arm64</li>
<li>Mach-O executable arm_v7</li>
</ul>
</li>
<li>.car，资源打包文件 .nib、.bundle、Localizable.strings</li>
<li>_CodeSignature签名文件<ul>
<li>文件hash列表：存放每个文件的hash值； </li>
<li>XML结构</li>
</ul>
</li>
<li>.mobileprovision </li>
</ul>
<p>可执行文件Mach-O通常有三部分组成</p>
<ul>
<li>头部 (Header): Mach-O文件的架构 比如Mac的 PPC, PPC64, IA-32, x86-64，ios的arm系列。</li>
<li>加载命令(Load commands): 在虚拟内存中指定文件的逻辑结构和布局。</li>
<li>原始段数据（Raw segment data）:可以拥有多个段（segment），每个段可以拥有零个或多个区域（section）。每一个段（segment）都拥有一段虚拟地址映射到进程的地址空间。</li>
</ul>
<img src="/blogwebpage/images/iOS/macho_construction.png" class="" title="Mach-O_Construction">

<ol>
<li><p>XCode开启编译选项Write Link Map File<br>XCode -&gt; Project -&gt; Build Settings -&gt; 搜map -&gt; 把Write Link Map File选项设为YES，并指定好linkMap的存储位置<br>特别提醒：打包发布前记得还原为NO</p>
</li>
<li><p>编译后，到编译目录里找到该txt文件，文件名和路径就是上述的Path to Link Map File位于</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">~<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/XXX-XXXXXXXXXXXX/</span>Build<span class="regexp">/Intermediates/</span>XXX.build<span class="regexp">/Debug-iphoneos/</span>XXX.build/</span><br><span class="line"></span><br><span class="line"><span class="regexp">//</span>example</span><br><span class="line"><span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build/<span class="number">4</span>dBookCity-LinkMap-normal-arm64.txt</span><br></pre></td></tr></table></figure>
<p>这个LinkMap里展示了整个可执行文件的全貌，列出了编译后的每一个.o目标文件的信息（包括静态链接库.a里的），以及每一个目标文件的代码段，数据段存储详情。</p>
</li>
</ol>
<h2 id="LinkMap结构"><a href="#LinkMap结构" class="headerlink" title="LinkMap结构"></a>LinkMap结构</h2><ol>
<li><p>首先列出来的是目标文件列表(中括号内为文件编号)：</p>
<figure class="highlight gradle"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"># Path: <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Products/</span>Debug-iphoneos<span class="regexp">/4dBookCity.app/</span><span class="number">4</span>dBookCity</span><br><span class="line"># Arch: arm64</span><br><span class="line"># Object files:</span><br><span class="line">[  <span class="number">0</span>] linker synthesized</span><br><span class="line">[  <span class="number">1</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/Bulk_Arrays_12.o</span><br><span class="line">[  <span class="number">2</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRSnapLearnInviteView.o</span><br><span class="line">[  <span class="number">3</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRPKHomeCellViewModel.o</span><br><span class="line">[  <span class="number">4</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/Bulk_Arrays_5.o</span><br><span class="line">[  <span class="number">5</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRBookStoreItemScrollTemplateCell.o</span><br><span class="line">[  <span class="number">6</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRAutoReadViewController.o</span><br><span class="line">[  <span class="number">7</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRQAExerciseQestionTitleView.o</span><br><span class="line">[  <span class="number">8</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/MXRMyTaskController.o</span><br><span class="line">[  <span class="number">9</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/UnityView.o</span><br><span class="line">[ <span class="number">10</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Intermediates.noindex/</span>huashida_home.build<span class="regexp">/Debug-iphoneos/</span><span class="number">4</span>dBookCity.build<span class="regexp">/Objects-normal/</span>arm64/main.o</span><br><span class="line">...</span><br><span class="line">[<span class="number">5229</span>] <span class="regexp">/Users/m</span>xr<span class="regexp">/Library/</span>Developer<span class="regexp">/Xcode/</span>DerivedData<span class="regexp">/huashida_home.xcodeproj-fvbzvmahuzlfgqbzehannctanrbl/</span>Build<span class="regexp">/Products/</span>Debug-iphoneos/libPods-<span class="number">4</span>dBookCity.a(Pods-<span class="number">4</span>dBookCity-dummy.o)</span><br><span class="line">[<span class="number">5230</span>] <span class="regexp">/Applications/</span>Xcode.app<span class="regexp">/Contents/</span>Developer<span class="regexp">/Toolchains/</span>XcodeDefault.xctoolchain<span class="regexp">/usr/</span>lib<span class="regexp">/arc/</span>libarclite_iphoneos.a(arclite.o)</span><br><span class="line">[<span class="number">5231</span>] <span class="regexp">/Applications/</span>Xcode.app<span class="regexp">/Contents/</span>Developer<span class="regexp">/Platforms/i</span>PhoneOS.platform<span class="regexp">/Developer/</span>SDKs<span class="regexp">/iPhoneOS11.2.sdk/u</span>sr<span class="regexp">/lib/</span>libobjc.tbd</span><br><span class="line">[<span class="number">5232</span>] <span class="regexp">/Applications/</span>Xcode.app<span class="regexp">/Contents/</span>Developer<span class="regexp">/Toolchains/</span>XcodeDefault.xctoolchain<span class="regexp">/usr/</span>lib<span class="regexp">/clang/</span><span class="number">9.0</span>.<span class="number">0</span><span class="regexp">/lib/</span>darwin/libclang_rt.ios.a(os_version_check.c.o)</span><br><span class="line">[<span class="number">5233</span>] <span class="regexp">/Applications/</span>Xcode.app<span class="regexp">/Contents/</span>Developer<span class="regexp">/Platforms/i</span>PhoneOS.platform<span class="regexp">/Developer/</span>SDKs<span class="regexp">/iPhoneOS11.2.sdk/</span>System<span class="regexp">/Library/</span>Frameworks<span class="comment">//AudioToolbox.framework/AudioToolbox.tbd</span></span><br><span class="line">[<span class="number">5234</span>] <span class="regexp">/Applications/</span>Xcode.app<span class="regexp">/Contents/</span>Developer<span class="regexp">/Platforms/i</span>PhoneOS.platform<span class="regexp">/Developer/</span>SDKs<span class="regexp">/iPhoneOS11.2.sdk/</span>System<span class="regexp">/Library/</span>Frameworks<span class="comment">//CoreVideo.framework/CoreVideo.tbd</span></span><br></pre></td></tr></table></figure></li>
<li><p>接着是一个段表，描述各个段在最后编译成的可执行文件中的偏移位置及大小，包括了代码段（__TEXT，保存程序代码段编译后的机器码）和数据段（__DATA，保存变量值）</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Sections:</span></span><br><span class="line"><span class="comment"># Address   Size        Segment Section</span></span><br><span class="line"><span class="attribute">0x100005B00</span> <span class="number">0</span>x<span class="number">0304</span>A<span class="number">29</span>C  __TEXT  __text</span><br><span class="line"><span class="attribute">0x10304FD9C</span> <span class="number">0</span>x<span class="number">00004</span>BC<span class="number">0</span>  __TEXT  __stubs</span><br><span class="line"><span class="attribute">0x10305495C</span> <span class="number">0</span>x<span class="number">000044</span>E<span class="number">8</span>  __TEXT  __stub_helper</span><br><span class="line"><span class="attribute">0x103058E50</span> <span class="number">0</span>x<span class="number">0021563</span>C  __TEXT  __cstring</span><br><span class="line"><span class="attribute">0x10326E48C</span> <span class="number">0</span>x<span class="number">000</span>AD<span class="number">400</span>  __TEXT  __objc_methname</span><br><span class="line"><span class="attribute">0x10331B88C</span> <span class="number">0</span>x<span class="number">0000</span>E<span class="number">6</span>BA  __TEXT  __objc_classname</span><br><span class="line"><span class="attribute">0x103329F46</span> <span class="number">0</span>x<span class="number">000166</span>E<span class="number">3</span>  __TEXT  __objc_methtype</span><br><span class="line"><span class="attribute">0x103340640</span> <span class="number">0</span>x<span class="number">002</span>A<span class="number">0</span>B<span class="number">60</span>  __TEXT  __const</span><br><span class="line"><span class="attribute">0x1035E11A0</span> <span class="number">0</span>x<span class="number">001346</span>D<span class="number">4</span>  __TEXT  __gcc_except_tab</span><br><span class="line"><span class="attribute">0x103715874</span> <span class="number">0</span>x<span class="number">00008</span>C<span class="number">78</span>  __TEXT  __ustring</span><br><span class="line"><span class="attribute">0x10371E4EC</span> <span class="number">0</span>x<span class="number">0004</span>D<span class="number">80</span>C  __TEXT  __unwind_info</span><br><span class="line"><span class="attribute">0x10376BCF8</span> <span class="number">0</span>x<span class="number">00000300</span>  __TEXT  __eh_frame</span><br><span class="line"><span class="attribute">0x10376C000</span> <span class="number">0</span>x<span class="number">000015</span>D<span class="number">8</span>  __DATA  __got</span><br><span class="line"><span class="attribute">0x10376D5D8</span> <span class="number">0</span>x<span class="number">00003280</span>  __DATA  __la_symbol_ptr</span><br><span class="line"><span class="attribute">0x103770858</span> <span class="number">0</span>x<span class="number">00001838</span>  __DATA  __mod_init_func</span><br><span class="line"><span class="attribute">0x103772090</span> <span class="number">0</span>x<span class="number">000</span>FF<span class="number">7</span>F<span class="number">8</span>  __DATA  __const</span><br><span class="line"><span class="attribute">0x103871888</span> <span class="number">0</span>x<span class="number">0006</span>F<span class="number">9</span>C<span class="number">0</span>  __DATA  __cfstring</span><br><span class="line"><span class="attribute">0x1038E1248</span> <span class="number">0</span>x<span class="number">00004778</span>  __DATA  __objc_classlist</span><br><span class="line"><span class="attribute">0x1038E59C0</span> <span class="number">0</span>x<span class="number">00000290</span>  __DATA  __objc_nlclslist</span><br><span class="line"><span class="attribute">0x1038E5C50</span> <span class="number">0</span>x<span class="number">00000708</span>  __DATA  __objc_catlist</span><br><span class="line"><span class="attribute">0x1038E6358</span> <span class="number">0</span>x<span class="number">00000038</span>  __DATA  __objc_nlcatlist</span><br><span class="line"><span class="attribute">0x1038E6390</span> <span class="number">0</span>x<span class="number">00000910</span>  __DATA  __objc_protolist</span><br><span class="line"><span class="attribute">0x1038E6CA0</span> <span class="number">0</span>x<span class="number">00000008</span>  __DATA  __objc_imageinfo</span><br><span class="line"><span class="attribute">0x1038E6CA8</span> <span class="number">0</span>x<span class="number">00206</span>C<span class="number">58</span>  __DATA  __objc_const</span><br><span class="line"><span class="attribute">0x103AED900</span> <span class="number">0</span>x<span class="number">00027</span>F<span class="number">28</span>  __DATA  __objc_selrefs</span><br><span class="line"><span class="attribute">0x103B15828</span> <span class="number">0</span>x<span class="number">000000</span>C<span class="number">0</span>  __DATA  __objc_protorefs</span><br><span class="line"><span class="attribute">0x103B158E8</span> <span class="number">0</span>x<span class="number">000041</span>B<span class="number">8</span>  __DATA  __objc_classrefs</span><br><span class="line"><span class="attribute">0x103B19AA0</span> <span class="number">0</span>x<span class="number">000030</span>C<span class="number">0</span>  __DATA  __objc_superrefs</span><br><span class="line"><span class="attribute">0x103B1CB60</span> <span class="number">0</span>x<span class="number">0000</span>BB<span class="number">54</span>  __DATA  __objc_ivar</span><br><span class="line"><span class="attribute">0x103B286B8</span> <span class="number">0</span>x<span class="number">0002</span>CB<span class="number">00</span>  __DATA  __objc_data</span><br><span class="line"><span class="attribute">0x103B551C0</span> <span class="number">0</span>x<span class="number">01</span>D<span class="number">52748</span>  __DATA  __data</span><br><span class="line"><span class="attribute">0x1058A7920</span> <span class="number">0</span>x<span class="number">00714878</span>  __DATA  __bss</span><br><span class="line"><span class="attribute">0x105FBD000</span> <span class="number">0</span>x<span class="number">0012</span>B<span class="number">978</span>  __DATA  __common</span><br></pre></td></tr></table></figure>
<p>首列是数据在文件的偏移位置，第二列是这一段占用大小，第三列是段类型，代码段和数据段，第四列是段名称。<br>每一行的数据都紧跟在上一行后面，如第二行__stubs的地址0x10304FD9C就是第一行__text的地址0x100005B00加上大小0x0304A29C，整个可执行文件大致数据分布就是这样。<br>这里可以清楚看到各种类型的数据在最终可执行文件里占的比例，例如__text表示编译后的程序执行语句，__data表示已初始化的全局变量和局部静态变量，__bss表示未初始化的全局变量和局部静态变量，__cstring表示代码里的字符串常量，等等。</p>
</li>
<li><p>接着就是按上表顺序，列出具体的按每个文件列出每个对应字段的位置和占用空间</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Symbols:</span></span><br><span class="line"><span class="comment"># Address   Size        File  Name</span></span><br><span class="line"><span class="number">0x100005B00</span> <span class="number">0x000000EC</span>  [  <span class="number">2</span>] <span class="string">-[MXRSnapLearnInviteView</span> <span class="string">drawRect:]</span></span><br><span class="line"><span class="number">0x100005BEC</span> <span class="number">0x0000024C</span>  [  <span class="number">2</span>] <span class="string">-[MXRSnapLearnInviteView</span> <span class="string">generatorlogoImageQRCode]</span></span><br><span class="line"><span class="number">0x100005E38</span> <span class="number">0x0000005C</span>  [  <span class="number">2</span>] <span class="string">_CGRectMake</span></span><br><span class="line"><span class="number">0x100005E94</span> <span class="number">0x00000034</span>  [  <span class="number">2</span>] <span class="string">-[MXRSnapLearnInviteView</span> <span class="string">inviteCode]</span></span><br><span class="line"><span class="number">0x100005EC8</span> <span class="number">0x00000050</span>  [  <span class="number">2</span>] <span class="string">-[MXRSnapLearnInviteView</span> <span class="string">setInviteCode:]</span></span><br><span class="line"><span class="number">0x100005F18</span> <span class="number">0x0000003C</span>  [  <span class="number">2</span>] <span class="string">-[MXRSnapLearnInviteView</span> <span class="string">.cxx_destruct]</span></span><br><span class="line"><span class="number">0x100005F54</span> <span class="number">0x000001D8</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">initWithModel:]</span></span><br><span class="line"><span class="number">0x10000612C</span> <span class="number">0x0000016C</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">encodeWithCoder:]</span></span><br><span class="line"><span class="number">0x100006298</span> <span class="number">0x00000268</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">initWithCoder:]</span></span><br><span class="line"><span class="number">0x100006500</span> <span class="number">0x00000040</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">desc]</span></span><br><span class="line"><span class="number">0x100006540</span> <span class="number">0x00000044</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">setDesc:]</span></span><br><span class="line"><span class="number">0x100006584</span> <span class="number">0x00000040</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">name]</span></span><br><span class="line"><span class="number">0x1000065C4</span> <span class="number">0x00000044</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">setName:]</span></span><br><span class="line"><span class="number">0x100006608</span> <span class="number">0x00000040</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">pic]</span></span><br><span class="line"><span class="number">0x100006648</span> <span class="number">0x00000044</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">setPic:]</span></span><br><span class="line"><span class="number">0x10000668C</span> <span class="number">0x00000040</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">classifyId]</span></span><br><span class="line"><span class="number">0x1000066CC</span> <span class="number">0x00000044</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">setClassifyId:]</span></span><br><span class="line"><span class="number">0x100006710</span> <span class="number">0x000000B8</span>  [  <span class="number">3</span>] <span class="string">-[MXRPKHomeCellViewModel</span> <span class="string">.cxx_destruct]</span></span><br><span class="line"><span class="string">...</span></span><br><span class="line"><span class="number">0x1060C82D0</span> <span class="number">0x000000C0</span>  [<span class="number">3391</span>] <span class="string">_jerrenv</span></span><br><span class="line"><span class="number">0x1060C8390</span> <span class="number">0x000204E0</span>  [<span class="number">4793</span>] <span class="string">_GC_arrays</span></span><br><span class="line"><span class="number">0x1060E8870</span> <span class="number">0x00000100</span>  [<span class="number">4793</span>] <span class="string">_GC_bm_table</span></span><br><span class="line"><span class="number">0x1060E8970</span> <span class="number">0x00000008</span>  [<span class="number">4793</span>] <span class="string">_GC_noop_sink</span></span><br></pre></td></tr></table></figure>
<p>同样首列是数据在文件的偏移地址，第二列是占用大小，第三列是所属文件序号，对应上述Object files列表，最后是名字。</p>
</li>
<li><p>已废弃&amp;多余重复的字段</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"># Dead Stripped Symbols:</span><br><span class="line">#           Size        File  Name</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000001</span>  [  <span class="number">1</span>] literal <span class="built_in">string</span>: </span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000005</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: desc</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000005</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: name</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: pic</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000B</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: classifyId</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000E</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: .cxx_destruct</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000B</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: <span class="symbol">v24@</span><span class="number">0</span>:<span class="symbol">8@</span><span class="number">16</span></span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: <span class="symbol">v16@</span><span class="number">0</span>:<span class="number">8</span></span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">3</span>] literal <span class="built_in">string</span>: @<span class="symbol">16@</span><span class="number">0</span>:<span class="number">8</span></span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000001</span>  [  <span class="number">4</span>] literal <span class="built_in">string</span>: </span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000007</span>  [  <span class="number">4</span>] literal <span class="built_in">string</span>: System</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000C</span>  [  <span class="number">4</span>] literal <span class="built_in">string</span>: UnityEngine</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000A</span>  [  <span class="number">4</span>] literal <span class="built_in">string</span>: System.IO</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] <span class="number">8</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000C</span>  [  <span class="number">5</span>] literal <span class="built_in">string</span>: PRIMARY KEY</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x0000000C</span>  [  <span class="number">5</span>] literal <span class="built_in">string</span>: FOREIGN KEY</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000001</span>  [  <span class="number">5</span>] literal <span class="built_in">string</span>: </span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000020</span>  [  <span class="number">5</span>] CFString</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000020</span>  [  <span class="number">5</span>] CFString</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Type_Text</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Type_Int</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Type_Double</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Type_Blob</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_NotNull</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_PrimaryKey</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_Default</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_Unique</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_Check</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Attribute_ForeignKey</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Convert_FloatType</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Convert_IntType</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Convert_BlobType</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Mapping_Inherit</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Mapping_Binding</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKSQL_Mapping_UserCalculate</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKDB_TypeKey</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKDB_TypeKey_Model</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKDB_TypeKey_JSON</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [  <span class="number">5</span>] _LKDB_TypeKey_Combo</span><br><span class="line">...</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4311</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4311</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4311</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4311</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [<span class="number">4311</span>] <span class="number">8</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000008</span>  [<span class="number">4312</span>] <span class="number">8</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000014</span>  [<span class="number">4320</span>] __ZN15PxcConvexMeshHLC2EP17PxConvexMeshData_</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4320</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4320</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000004</span>  [<span class="number">4319</span>] <span class="number">4</span>-byte-literal</span><br><span class="line">&lt;&lt;dead&gt;&gt;    <span class="number">0x00000076</span>  [<span class="number">4319</span>] literal <span class="built_in">string</span>: /Applications/buildAgent/work/<span class="number">3</span>d1e9e6e6eefaa7f/SDKs/compiler/iphone/../../../LowLevel/common/include/utils/PxcArray.h</span><br></pre></td></tr></table></figure>
<p>这个文件可以让你了解整个APP编译后的情况，也许从中可以发现一些异常，还可以用这个文件计算静态链接库在项目里占的大小，有时候我们在项目里链了很多第三方库，导致APP体积变大很多，我们想确切知道每个库占用了多大空间，可以给我们优化提供方向。LinkMap里有了每个目标文件每个方法每个数据的占用大小数据，所以只要写个脚本，就可以统计出每个.o最后的大小，属于一个.a静态链接库的.o加起来，就是这个库在APP里占用的空间大小。</p>
</li>
</ol>
<h2 id="关于Xcode的Other-Linker-Flags"><a href="#关于Xcode的Other-Linker-Flags" class="headerlink" title="关于Xcode的Other Linker Flags"></a>关于Xcode的Other Linker Flags</h2><ul>
<li>背景</li>
</ul>
<p>在ios开发过程中，有时候会用到第三方的静态库(.a文件)，然后导入后发现编译正常但运行时会出现selector not recognized的错误，从而导致app闪退。接着仔细阅读库文件的说明文档，你可能会在文档中发现诸如在Other Linker Flags中加入-ObjC或者-all_load这样的解决方法。<br>那么，Other Linker Flags到底是用来干什么的呢？还有-ObjC和-all_load到底发挥了什么作用呢？</p>
<ul>
<li>链接器</li>
</ul>
<p>首先，要说明一下Other Linker Flags到底是用来干嘛的。说白了，就是ld命令除了默认参数外的其他参数。ld命令实现的是链接器的工作，详细说明可以在终端man ld查看。<br>如果有人不清楚链接器是什么东西的话，我可以作个简单的说明。<br>一个程序从简单易读的代码到可执行文件往往要经历以下步骤：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">源代码 &gt; 预处理器 &gt; 编译器 &gt; 汇编器 &gt; 机器码 &gt; 链接器 &gt; 可执行文件</span><br></pre></td></tr></table></figure>
<p>源文件经过一系列处理以后，会生成对应的.obj文件，然后一个项目必然会有许多.obj文件，并且这些文件之间会有各种各样的联系，例如函数调用。链接器做的事就是把这些目标文件和所用的一些库链接在一起形成一个完整的可执行文件。</p>
<ul>
<li>为什么会闪退</li>
</ul>
<p>Objective-C的链接器并不会为每个方法建立符号表，而是仅仅为类建立了符号表。这样的话，如果静态库中定义了已存在的一个类的分类，链接器就会以为这个类已经存在，不会把分类和核心类的代码合起来。这样的话，在最后的可执行文件中，就会缺少分类里的代码，这样函数调用就失败了。</p>
<ul>
<li>解决方法</li>
</ul>
<p>解决方法在背景那块我就提到了，就是在Other Linker Flags里加上所需的参数，用到的参数一般有以下3个：</p>
<figure class="highlight autohotkey"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">`-ObjC`       : 链接器会把静态库中所有的类和分类都加载到最后的可执行文件中</span><br><span class="line">`-force_load` : 需要指定要进行全部加载的库文件的路径,避免引用多个第三方库时会出现类名重叠的冲突</span><br><span class="line">`-all_load`   : 让链接器把所有找到的目标文件都加载到可执行文件中，不建议使用</span><br><span class="line">`-dead_strip` : 删除多余的库符号，不建议使用</span><br></pre></td></tr></table></figure>
<p>在编译Objective-C源文件到目标文件时，编译器并不知道方法的对应实现，只能在运行时才知道，所以编译器只会为类生成链接符号，对类中的方法不会生成链接符号。由于Category方法并不对应一个新类，所以不会生成链接符号，链接器也不会将Category方法合并到原始的类中，最终导致链接器忽略了Category方法，不会将其链接到可执行文件中。</p>
<p>当静态库中只有分类而没有类的时候，-ObjC参数就会失效了。这时候，就需要使用-all_load或者-force_load了。<br>-all_load会让链接器把所有找到的目标文件都加载到可执行文件中，但是千万不要随便使用这个参数！假如你使用了不止一个静态库文件，然后又使用了这个参数，那么你很有可能会遇到ld: duplicate symbol错误，因为不同的库文件里面可能会有相同的目标文件，所以建议在遇到-ObjC失效的情况下使用-force_load参数。<br>-force_load所做的事情跟-all_load其实是一样的，但是-force_load需要指定要进行全部加载的库文件的路径，这样的话，你就只是完全加载了一个库文件，不影响其余库文件的按需加载。<br>在能拿到静态库源码情况下，建议对.a库重新打包，删除部分重复的symbol。<br>在拿不到静态库源码情况下 ,只能采用-force_load+库文件路径方法设置Other Linker Flags,逐个加静态库,最终完美解决两个静态库存在同名文件冲突,发现那个静态库无法调用,就采用以下语句添加进去。<br>-force_load EightPartyCall/standaloneclass/BaiduSocialShare/WX/libWeChatSDK<br>(-force_load后面为静态库文件路径,根据自己项目对应路径)</p>
<p>也可以拆分静态库</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">$ cd /LibSDK </span><br><span class="line">$ ls</span><br><span class="line">libiot<span class="selector-class">.sdk</span>.a</span><br><span class="line">$ lipo -info libiot<span class="selector-class">.sdk</span>.a</span><br><span class="line">Architectures <span class="keyword">in</span> the fat file: libiot<span class="selector-class">.sdk</span><span class="selector-class">.a</span> are: armv7 arm64 </span><br><span class="line">$  lipo libiot<span class="selector-class">.sdk</span><span class="selector-class">.a</span> -thin armv7 -output tbv7.a</span><br><span class="line">$  lipo libiot<span class="selector-class">.sdk</span><span class="selector-class">.a</span> -thin arm64 -output tb64.a</span><br><span class="line">$ ls</span><br><span class="line">libiot<span class="selector-class">.sdk</span><span class="selector-class">.a</span>        tb64<span class="selector-class">.a</span>      tbv7.a</span><br><span class="line">$ ar -d tbv7<span class="selector-class">.a</span> AsyncSocket.o</span><br><span class="line">$ ar -d tb64<span class="selector-class">.a</span> AsyncSocket.o</span><br><span class="line">$ lipo -create tbv7<span class="selector-class">.a</span> tbv64<span class="selector-class">.a</span> -output libSun.a</span><br></pre></td></tr></table></figure>

<p>lipo源于mac系统要制作兼容powerpc平台和intel平台的程序。<br>lipo 是一个在 Mac OS X 中处理通用程序（Universal Binaries）的工具。现在发售或者提供下载的许多（几乎所有）程序都打上了“Universal”标志，意味着它们同时具有 PowerPC 和 Intel 芯片能够处理的代码。不过既然你可能不在意其中的一个，你就能够使用 lipo 来给你的程序“瘦身”。</p>
<h2 id="写了一堆乱七八糟的"><a href="#写了一堆乱七八糟的" class="headerlink" title="写了一堆乱七八糟的"></a>写了一堆乱七八糟的</h2><p>参考app包优化<br><span class="exturl" data-url="aHR0cHM6Ly93d3cuamlhbnNodS5jb20vcC9hMzE1MWRmZWJjOWM=">干货|今日头条iOS端安装包大小优化—思路与实践<i class="fa fa-external-link-alt"></i></span></p>

    </div>

    
    
    
        <div class="reward-container">
  <div>希望对您有所帮助，您的支持将是我莫大的动力！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/blogwebpage/images/wechatpay.png" alt="Jack Wang 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/blogwebpage/images/alipay.png" alt="Jack Wang 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blogwebpage/tags/ipa%E5%8C%85%E5%88%86%E6%9E%90/" rel="tag"># ipa包分析</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blogwebpage/vue/qa.html" rel="prev" title="Vue知识">
      <i class="fa fa-chevron-left"></i> Vue知识
    </a></div>
      <div class="post-nav-item">
    <a href="/blogwebpage/iOS/interview/nsurlsession-connection.html" rel="next" title="NSURLSession与NSURLConnection区别">
      NSURLSession与NSURLConnection区别 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#LinkMap%E7%BB%93%E6%9E%84"><span class="nav-number">1.</span> <span class="nav-text">LinkMap结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%85%B3%E4%BA%8EXcode%E7%9A%84Other-Linker-Flags"><span class="nav-number">2.</span> <span class="nav-text">关于Xcode的Other Linker Flags</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%86%99%E4%BA%86%E4%B8%80%E5%A0%86%E4%B9%B1%E4%B8%83%E5%85%AB%E7%B3%9F%E7%9A%84"><span class="nav-number">3.</span> <span class="nav-text">写了一堆乱七八糟的</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jack Wang"
      src="/blogwebpage/images/avatar.gif">
  <p class="site-author-name" itemprop="name">Jack Wang</p>
  <div class="site-description" itemprop="description">书山有路勤为径，学海无涯苦作舟！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blogwebpage/archives/">
        
          <span class="site-state-item-count">52</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blogwebpage/categories/">
          
        <span class="site-state-item-count">56</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blogwebpage/tags/">
          
        <span class="site-state-item-count">54</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL0phY2stVmluZw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Jack-Ving"><i class="github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjcyNzg4MTk0NUBxcS5jb20=" title="E-Mail → mailto:727881945@qq.com"><i class="envelope fa-fw"></i>E-Mail</span>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><span class="exturl" data-url="aHR0cHM6Ly9iZWlhbi5taWl0Lmdvdi5jbg==">京ICP备16036665号-2 </span>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jack Wang</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        


  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1277804316&web_id=1277804316"></script>
  </div>






      </div>
    </footer>
  </div>

  
  <script src="/blogwebpage/lib/anime.min.js"></script>
  <script src="/blogwebpage/lib/velocity/velocity.min.js"></script>
  <script src="/blogwebpage/lib/velocity/velocity.ui.min.js"></script>

<script src="/blogwebpage/js/utils.js"></script>

<script src="/blogwebpage/js/motion.js"></script>


<script src="/blogwebpage/js/schemes/pisces.js"></script>


<script src="/blogwebpage/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/blogwebpage/js/local-search.js"></script>













  

  

</body>
</html>
